﻿#r @"C:\Users\Johan\Documents\Visual Studio 10\Projects\Livingston Web Framework\WingBeats\bin\Debug\WingBeats.dll"
#r @"C:\Users\Johan\Documents\Visual Studio 10\Projects\Livingston Web Framework\Liv.Examples\bin\Debug\Liv.Examples.dll"

open WingBeats
open WingBeats.XHTML
open WingBeats.XHTML.CoreBeats
open WingBeats.XHTML.FormBeats
open WingBeats.Transform
open WingBeats.DataMapping

type gender = | Male | Female

type Person =
    {
        FirstName : string
        LastName  : string
        Age       : int
        Gender    : gender
    }
    
let mapPerson (person  : Person) =
    mapping 
        (person.FirstName + person.LastName)
        [
            section "Name"
                [
                    property "First name"  person.FirstName
                    property "Second name" person.LastName
                ]
                
            property "Age" person.Age
            
            singleChoice "Gender" 
                [
                    choice "Male"   gender.Male   (person.Gender.Equals(gender.Male))
                    choice "Female" gender.Female (person.Gender.Equals(gender.Female))
                ]
        ]
    
let mappedMe =
    {
        FirstName = "Johan"
        LastName  = "Jonasson"
        Age       = 33
        Gender    = Male
    }
    |> mapPerson
    
//type e =
//    static member div (?Id: string, ?Class: string list, ?Selector: string, ?Content: WingBeats.part list, ?Inner: string) =
//        div
//            (
//                (match Id with | None -> [] | Some v -> [A.Id v])
//                @(match Class with | None -> [] | Some v -> [A.Class v])
//            )
//            (
//                match Content with 
//                | None -> 
//                    (match Inner with | None -> [] | Some v -> [WingBeats.Inner v])
//                | Some v -> v
//            )
//
//let div1 = e.div ()
//let div2 =
//    e.div(
//        Id = "test", 
//        Class= "text-class",
//        Content =
//            [
//                e.div (
//                    Content =   [
//                                    e.div()
//                                ])
//                e.div ()
//            ]) 

let twoColumnPage title mainColContent subColContent =
    
    let jQueryUrl = "/scripts/jQuery.js"
    let resetCss  = "/style/reset.css"
    let mainCss   = "/main.css"
    
    // The code below is WingBeats code
    Html
        {
            Title    = title
            Language = D.English
            Head =
                [
                    Stylesheet [D.Screen] resetCss
                    Stylesheet [D.Screen] mainCss
                    JavaScriptRef jQueryUrl
                ]
            Body =
                [
                    div "#main-column.text"
                        (H1 title :: mainColContent)
                    div "#sub-column.text"
                        subColContent
                ]
        }

open WingBeats
open WingBeats.XHTML
open WingBeats.XHTML.CoreBeats
open WingBeats.Transform

let pageStructure = 
    Html
        {
            Title    = ""
            Language = D.English
            Head     = []
            Body =
                [
                    div "#page"
                        [
                            div "#header.mod" []
                            div "#main.mod" []
                            div "#footer.mod" []
                        ]
                ] 
        }
        
let updatedStructure =
    let modStructure =
        [
            div ".mod-head" []
            div ".mod-body" []
            div ".mod-footer" []
        ]
    pageStructure
    |> Add (".mod", modStructure)
    |> Add ("#main .mod-body", ".text-column")